﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Snowdreamist.Runtime;
using Snowdreamist.Runtime.Services;

namespace Snowdreamist.ComponentModel.MEF
{
    public class MEFModuleActivator : IModuleActivator
    {
        public virtual void Initialize() { }

        public virtual IModule Active(IModuleDefinition definition)
        {
            if (definition == null)
                throw new ArgumentNullException("definition");
            if (!(definition is MEFModuleDefinition))
                throw new InvalidOperationException("Wrong definition type");

            return ((MEFModuleDefinition)definition).Value;
        }

        public virtual void Deactive(IModuleDefinition definition, IModule instance)
        {
            // nothing
        }

        public virtual void OnRuntimeDisposing() { }
    }
}